<?php
	include $setupdata['core_dir']."/modules/payment/gateway/sebclass.php";
	$sebclass = new sebclass;
	
	if ($act=="save"){
		$seb_data = array();
		if (isset($_POST["VK_SND_ID"])) $seb_data['VK_SND_ID']=$_POST["VK_SND_ID"]; else $seb_data['VK_SND_ID']="";
		if (isset($_POST["VK_ACC"])) $seb_data['VK_ACC']=$_POST["VK_ACC"]; else $seb_data['VK_ACC']="";
		if (isset($_POST["VK_NAME"])) $seb_data['VK_NAME']=$_POST["VK_NAME"]; else $seb_data['VK_NAME']="";
		if (isset($_POST["VK_LANG"])) $seb_data['VK_LANG']=$_POST["VK_LANG"]; else $seb_data['VK_LANG']="";
		if (isset($_POST["VK_CURR"])) $seb_data['VK_CURR']=$_POST["VK_CURR"]; else $seb_data['VK_CURR']="";
		if (isset($_POST["VK_PASS"])) $seb_data['VK_PASS']=$_POST["VK_PASS"]; else $seb_data['VK_PASS']="";
		if (isset($_POST["KEY_PRIV"])) $seb_data['KEY_PRIV']=$_POST["KEY_PRIV"]; else $seb_data['KEY_PRIV']="";
		if (isset($_POST["KEY_PUBL"])) $seb_data['KEY_PUBL']=$_POST["KEY_PUBL"]; else $seb_data['KEY_PUBL']="";
		if (isset($_POST["PayURL"])) $seb_data['PayURL']=$_POST["PayURL"]; else $seb_data['PayURL']="";
		if (isset($_POST["target"])) $seb_data['target']=$_POST["target"]; else $seb_data['target']="_seb";
		
		if (openssl_get_privatekey($seb_data['KEY_PRIV'], $seb_data['VK_PASS']) === false) $err->AddError(26, "payment_seb");
		if (openssl_get_publickey($seb_data['KEY_PUBL']) === false) $err->AddError(27, "payment_seb");

		foreach($seb_data as $seb_key=>$seb_value) {
			if (($seb_value == "") && ($seb_key != 'VK_PASS')) $err->AddError(25, "payment_seb");
			else $seb_data[$seb_key] = trim($seb_data[$seb_key]);
		}
		
		if (isset($_POST["URL_OK"])) $seb_data['URL_OK']=trim($_POST["URL_OK"]); else $seb_data['URL_OK']="";
		if (isset($_POST["URL_CANCEL"])) $seb_data['URL_CANCEL']=trim($_POST["URL_CANCEL"]); else $seb_data['URL_CANCEL']="";

		$seb = addslashes(serialize($seb_data));
		$mysqlclass->mysql_my_query("DELETE FROM `".$setupdata['table_prefix']."local_vars` WHERE 'payment_gateway_seb'=`name`", __LINE__, __FILE__);
		$mysqlclass->mysql_my_query("INSERT INTO `".$setupdata['table_prefix']."local_vars` (`id`,`name`,`value`) VALUES ('', 'payment_gateway_seb', '".$seb."')", __LINE__, __FILE__);
		
		unset($seb_tmp);
		unset($seb_data);
		unset($seb_key);
		unset($seb);
		
	} elseif ($act == "status") {
		$res = $sebclass->return_order($_POST);
	} elseif ($act == "return") {
		$data = $paymentclass->get_gateway_data('seb');
		if (($res == 'pay') && (isset($data['URL_OK'])) && (strlen($data['URL_OK'])>6)) $str = '"'.$data['URL_OK'].'"';			
		elseif (($res == 'notpay') && (isset($data['URL_CANCEL'])) && (strlen($data['URL_CANCEL'])>6)) $str = '"'.$data['URL_CANCEL'].'"';		
		else $str = "window.opener.location.href";
		print_r('
			<script language="javascript1.4" type="text/javascript">
				url = '.$str.';
				window.opener.location.replace(url);
				window.close();
			</script>
		');
		$mysqlclass->close_db();
		die();
	}
?>